﻿@using Newtouch.Common.Operator
@using Newtouch.Herp.Infrastructure.Enum
@{
    ViewBag.Title = "物资维护";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="fa fa-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a class="btn btn-primary" onclick="btn_add()"><i class="fa fa-plus"></i>新建</a>
        </div>
        <div class="btn-group">
            <a class="btn btn-primary" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改</a>
        </div>
        <div class="btn-group">
            <a class="btn btn-primary" onclick="btn_delete()"><i class="fa fa fa-trash-o"></i>删除</a>
        </div>
    </div>
    <div class="search">
        <table>
            <tr>
                <td class="formTitle">类别：</td>
                <td class="formValue formDdlSelectorTd">
                    <div class="input-group">
                        <select class="form-control" id="lb">
                            <option value="">全部</option>
                        </select>
                    </div>
                </td>
                <td class="formTitle" style="padding-left:10px;">物资状态：</td>
                <td class="formValue formDdlSelectorTd" style="width:75px">
                    <div class="input-group">
                        @Html.DropDownList("wzzt", Enumzt.Enable.ToDescSelectList(), "全部", new { @class = "form-control" })
                    </div>
                </td>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="名称/拼音" style="width: 180px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
<script lang="javascript">
    $(function () {
        init();
        gridList();
    });
    function init() {

        $("#lb").bindSelect({
            url: "/ProductManage/ProductType/GetPatientTreeSelectJson"
        });
    }

    //get data
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/ProductManage/Product/GetProductGridJson",
            postData: {
                lb: $("#lb option:selected").val(),
                zt: $("#wzzt option:selected").val(),
                keyWord: $("#txt_keyword").val()
            },
            height: $(window).height() - 120,
            colModel: [
                { label: "主键", name: "Id", hidden: true, key: true },
                { label: '物资名称', name: 'name', width: 130, align: 'left' },
                { label: '国家医保码', name: 'gjybdm', width: 100, align: 'left' },
                { label: '类别', name: 'typeName', width: 190, align: 'left' },
                { label: '品牌', name: 'brand', width: 120, align: 'left' },
                { label: '型号规格', name: 'gg', width: 120, align: 'left' },
                { label: '最小单位', name: 'minUnit', width: 60, align: 'left' },
                { label: '生产商', name: 'supplierName', width: 150, align: 'left' },
                {
                    label: "有效", name: "zt", width: 50, align: "center",
                    formatter: function (cellvalue) { return cellvalue === "1" ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>"; }
                },
                { label: '创建人', name: 'CreatorCode', width: 70, align: 'left' },
                { label: '创建时间', name: 'CreateTime', width: 110, align: 'left', formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i', newformat: 'Y-m-d H:i' } },
                { label: '最后修改', name: 'LastModifierCode', hidden: true },
                { label: '最后修改时间', name: 'LastModifyTime', hidden: true },
                { label: 'OrganizeId', name: 'OrganizeId', hidden: true }
            ],
            pager: "#gridPager",
            sortname: 'CreateTime desc',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam',
            {
                postData: {
                    lb: $("#lb option:selected").val(),
                    zt: $("#wzzt option:selected").val(),
                    keyWord: $("#txt_keyword").val()
                }
            }).trigger('reloadGrid');
        });
    }

    //回车触发查询事件
    $("#txt_keyword").keydownEnterEvent(function() {
        $("#btn_search").trigger("click");
    });

    //新增
    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "新增物资",
            url: "/ProductManage/Product/Form",
            width: "750px",
            height: "750px",
            showleftlalbel: true,//新增时显示'确认并关闭按钮'
            leftlalbelchecked: false,
            leftlabeltext: "连续录入",
            leftlalbelcheckedasClose: false,
            callBack: function (iframeId, isClose) {
                $.currentWindow(iframeId).AcceptClick(function () {
                    $('#gridList').jqGrid("clearGridData"); //清除明细的grid
                    $("#gridList").resetSelection();
                    $("#gridList").trigger("reloadGrid");
                    if(isClose == undefined || isClose === true) {
                        top.frames[iframeId].$.modalClose();
                    }
                });
            }
        });
    }

    //修改
    function btn_edit() {
        var keyValue = $("#gridList").jqGridRowValue().Id;
        if (!!!keyValue) {
            $.modalAlert("请选中一条信息", 'warning');
            return;
        }
        @*var thisOrgId = $("#gridList").jqGridRowValue().OrganizeId;
        if (!!!thisOrgId && '@(!string.IsNullOrEmpty(OperatorProvider.GetCurrent().OrganizeId) && OperatorProvider.GetCurrent().OrganizeId != OperatorProvider.GetCurrent().TopOrganizeId)' === 'True') {
            $.modalAlert("无权限修改", 'warning');
            return;
        }*@
        $.modalOpen({
            id: "Form",
            title: "修改物资",
            url: "/ProductManage/Product/Form?keyValue=" + keyValue,
            width: "750px",
            height: "750px",
            leftlalbelchecked: false,
            leftlalbelcheckedasClose: false,
            callBack: function (iframeId) {
                $.currentWindow(iframeId).AcceptClick(function() {
                    $('#gridList').jqGrid("clearGridData"); //清除明细的grid
                    $("#gridList").resetSelection();
                    $("#gridList").trigger("reloadGrid");
                    top.frames[iframeId].$.modalClose();
                });
            }
        });
    }

    //删除
    function btn_delete() {
        var keyValue = $("#gridList").jqGridRowValue().Id;
        if (!!!keyValue) {
            $.modalAlert("请选中一条信息", 'warning');
            return;
        }
        @*var thisOrgId = $("#gridList").jqGridRowValue().OrganizeId;
        if (!!!thisOrgId && '@(!string.IsNullOrEmpty(OperatorProvider.GetCurrent().OrganizeId) && OperatorProvider.GetCurrent().OrganizeId != OperatorProvider.GetCurrent().TopOrganizeId)' === 'True') {
            $.modalAlert("无权限修改", 'warning');
            return;
        }*@
        $.deleteForm({
            url: "/ProductManage/Product/DeleteForm",
            param: { keyValue: keyValue },
            success: function () {
                $('#gridList').jqGrid("clearGridData"); //清除明细的grid
                $("#gridList").resetSelection();
                $("#gridList").trigger("reloadGrid");
            }
        });
    }

</script>